package com.petshop.controller;

import com.petshop.dto.OrderDTO;
import com.petshop.pojo.Orders;
import com.petshop.service.OrdersService;
import com.petshop.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    /*
    增加一条订单
     */
    @PostMapping("/insertOrder")
    public Result insertOrder(@RequestBody OrderDTO orderDTO,
                              @RequestHeader("Authorization") String token) {
        Result result = ordersService.insertOrder(orderDTO, token);
        return result;
    }

    /*
    删除一条订单
     */
    @GetMapping("/deleteOrder")
    public Result deleteOrder(@RequestParam Integer orderId) {
        Result result = ordersService.deleteOrder(orderId);
        return result;
    }

    /*
    根据token获取用户的地址信息
     */
    @GetMapping("/getUserAddress")
    public Result getUserAddress(@RequestHeader("Authorization") String token) {
        Result result = ordersService.getUserAddress(token);
        return result;
    }

    /*
    修改订单信息
     */
    @PostMapping("/updateOrder")
    public Result updateOrder(@RequestBody Orders orders) {
        Result result = ordersService.updateOrder(orders);
        return result;
    }

    /*
    修改订单状态
     */
    @GetMapping("/updateOrderStatus")
    public Result updateOrderStatus(Integer orderId) {
        Result result = ordersService.updateOrderStatus(orderId);
        return result;
    }

    /*
    用户查询自己的所有订单
     */
    @GetMapping("/queryAllOrder")
    public Result queryAllOrder(@RequestHeader("Authorization") String token) {
        Result result = ordersService.queryAllOrder(token);
        return result;
    }

    /*
    管理员获取所有用户的所有订单信息
     */
    @GetMapping("/queryAllOrders")
    public Result queryAllOrders(Integer flag, String status, Integer pageCount, Integer pageSize) {
        Result result = ordersService.queryAllOrders( flag,  status,  pageCount,  pageSize);
        return result;
    }

    /*
    根据id查询订单信息
     */
    @GetMapping("/queryById")
    public Orders queryById(@RequestParam Integer orderId) {
        Orders orders = ordersService.queryById(orderId);
        return orders;
    }

    /*
    根据订单状态查询订单信息
     */
    @GetMapping("/queryOrderByStatus")
    public Result queryOrderByStatus(String status) {
        Result result = ordersService.queryOrderByStatus(status);
        return result;
    }

    /*
    根据商品名查询
     */
    @GetMapping("/queryOrderByName")
    public Result queryOrderByName(String name) {
        Result result = ordersService.queryOrderByName(name);
        return result;
    }
}
